{Core} Honor scopes specified by Track 2 SDK#15184
Conversation
|
Core |
| profile = Profile(cli_ctx=cmd.cli_ctx) | ||
| n.token_credential, _, _ = profile.get_login_credentials( | ||
| resource="https://storage.azure.com", subscription_id=n._subscription) | ||
| n.token_credential, _, _ = profile.get_login_credentials(subscription_id=n._subscription) |
There was a problem hiding this comment.
scope is now managed by Track 2 Storage SDK (azure/multiapi/storagev2/blob/v2019_12_12/_shared/constants.py:25):
STORAGE_OAUTH_SCOPE = "https://storage.azure.com/.default"|
Unfortunately, due an incorrect
|
| # Deal with an old Track 2 SDK issue where the default credential_scopes is extended with | ||
| # custom credential_scopes. Instead, credential_scopes should be replaced by custom credential_scopes. | ||
| # https://github.com/Azure/azure-sdk-for-python/issues/12947 | ||
| # We simply remove the first one if there are multiple scopes provided. | ||
| if len(scopes) > 1: | ||
| scopes = scopes[1:] |
There was a problem hiding this comment.
Add a patch to handle issue Azure/azure-sdk-for-python#12947 in old Track 2 SDKs.
# Conflicts: # src/azure-cli-core/azure/cli/core/adal_authentication.py
| :rtype: str | ||
| """ | ||
| scope = scopes[0] | ||
| if scope.endswith(".default"): |
There was a problem hiding this comment.
if scope.endswith(".default"): [](start = 4, length = 30)
Do we need make this case insensitive?
There was a problem hiding this comment.
No. .default is the only supported form. See The /.default scope.
|
|
||
| # Trim extra ending slashes. https://datalake.azure.net// -> https://datalake.azure.net/ | ||
| scope = scope.rstrip('/') + '/' | ||
| return scope |
There was a problem hiding this comment.
Is it expected that "scope" is https://management.core.windows.net/ or it should be https://management.core.windows.net?
There was a problem hiding this comment.
Yes. See
| :return: The ADAL resource | ||
| :rtype: str | ||
| """ | ||
| scope = scopes[0] |
There was a problem hiding this comment.
Do we only support one scope now as it is a list?
There was a problem hiding this comment.
The scopes must all be from a single resource, along with OIDC scopes (profile, openid, email)
| :param resource: The ADAL resource ID | ||
| :return: A list of scopes | ||
| """ | ||
| if 'datalake' in resource or 'batch' in resource or 'database' in resource: |
There was a problem hiding this comment.
Is it possible that we move this tricky logic from core to module level?
There was a problem hiding this comment.
Good point. Currently resource_to_scopes is only called by _get_mgmt_service_client. We should actually remove this tricky logic totally from this function. Will do in a separate PR.
Fix #15179
Issue
In
scopes(resource) is managed by Azure CLIscopes(resource) is managed by SDKFor example, for Track 2 SDK mgmt-plane
SubscriptionClientConfiguration:For Track 2 SDK data-plane
AzureAppConfigurationClient:But in
AdalAuthentication.get_token,scopesis not honored (discarded), resulting in getting a token for a wrongscopes(ARMhttps://management.core.windows.net/by default):azure-cli/src/azure-cli-core/azure/cli/core/adal_authentication.py
Lines 61 to 67 in c2b9a2c
Fix
This PR fixes the issue by honoring the
scopesspecified by Track 2 SDK.Testing Guide
User Identity
Managed Identity